/**
 * @author jc
 * @description 所有全局配置的状态管理，如无必要请勿修改
 */

import defaultSettings from '@/config'

const { tabsBar, layout, logo, header, themeBar } = defaultSettings
const theme =
  JSON.parse(localStorage.getItem('client-info-web-theme')) || ''
const state = () => ({
  tabsBar: theme.tabsBar || tabsBar,
  logo,
  baseColor: theme.baseColor || '#2474b5',
  funcUnit: theme.funcUnit || '',
  tagsView: theme.tagsView || true,
  notice: theme.notice || true,
  header: theme.header || header,
  layout: theme.layout || layout,
  collapse: false,
  device: 'desktop',
  themeBar
})
const getters = {
  collapse: (state) => state.collapse,
  tabsBar: (state) => state.tabsBar,
  logo: (state) => state.logo,
  layout: (state) => state.layout,
  baseColor: (state) => state.baseColor,
  funcUnit: (state) => state.funcUnit,
  tagsView: (state) => state.tagsView,
  notice: (state) => state.notice,
  header: (state) => state.header,
  years: (state) => state.years,
  device: (state) => state.device,
  themeBar: (state) => state.themeBar
}
const mutations = {
  changeLayout: (state, layout) => {
    if (layout) state.layout = layout
  },
  changeTabsBar: (state, tabsBar) => {
    if (tabsBar) state.tabsBar = tabsBar
  },
  changeBaseColor: (state, baseColor) => {
    if (baseColor) state.baseColor = baseColor
  },
  changeFuncUnit: (state, funcUnit) => {
    if (funcUnit) state.funcUnit = funcUnit
  },
  changeTagsView: (state, tagsView) => {
    if (tagsView) state.tagsView = tagsView
  },
  changeNotice: (state, notice) => {
    if (notice) state.notice = notice
  },
  changeHeader: (state, header) => {
    if (header) state.header = header
  },
  changeYears: (state, years) => {
    if (years) state.years = years
  },
  openSideBar: (state) => {
    state.collapse = false
  },
  toggleDevice: (state, device) => {
    state.device = device
  },
  changeCollapse: (state) => {
    state.collapse = !state.collapse
  }
}
const actions = {
  changeLayout({ commit }, layout) {
    commit('changeLayout', layout)
  },
  setScanDevice({ commit }, scanDevice) {
    commit('setScanDevice', scanDevice)
  },
  changeTabsBar({ commit }, tabsBar) {
    commit('changeTabsBar', tabsBar)
  },
  changeBaseColor({ commit }, baseColor) {
    commit('changeBaseColor', baseColor)
  },
  changeFuncUnit({ commit }, funcUnit) {
    commit('changeFuncUnit', funcUnit)
  },
  changeTagsView({ commit }, tagsView) {
    commit('changeTagsView', tagsView)
  },
  changeNotice({ commit }, notice) {
    commit('changeNotice', notice)
  },
  changeHeader({ commit }, header) {
    commit('changeHeader', header)
  },
  changeYears({ commit }, years) {
    commit('changeYears', years)
  },
  openSideBar({ commit }) {
    commit('openSideBar')
  },
  toggleDevice({ commit }, device) {
    commit('toggleDevice', device)
  },
  changeCollapse({ commit }) {
    commit('changeCollapse')
  }
}
export default { state, getters, mutations, actions }
